package com.teacher.pc.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.teacher.common.CommonResult;
import com.teacher.pojo.dto.aestheticeducationbasic.AestheticEducationBasicGetDto;
import com.teacher.pojo.dto.aestheticeducationbasic.AestheticEducationBasicUpdateDto;
import com.teacher.pojo.entity.AestheticEducationBasic;
import com.teacher.pojo.vo.aestheticeducationbasic.AestheticEducationBasicGetVo;
import com.teacher.service.IAestheticEducationBasicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 美育基本分 前端控制器
 * </p>
 *
 * @author zfm
 * @since 2021-08-13
 */
@RestController
@RequestMapping("/pc/aesthetic-education-basic")
@Api(tags = "美育基本分")
public class AestheticEducationBasicController {

    @Autowired
    private IAestheticEducationBasicService iAestheticEducationBasicService;

    /**
     * 初始化美育基本分
     *
     * @param classId
     * @return
     */
    @PostMapping("/{classId}")
    @ApiOperation("初始化美育基本分 aestheticEducation_initialize")
    @PreAuthorize("hasAuthority('aestheticEducation_initialize')")
    public CommonResult<String> init(@PathVariable("classId") Long classId) {
        return iAestheticEducationBasicService.init(classId);
    }

    /**
     * 更新德育基础分
     *
     * @param dto
     * @return
     */
    @PutMapping
    @ApiOperation("更新德育基础分 aestheticEducation_update")
    @PreAuthorize("hasAuthority('aestheticEducation_update')")
    public CommonResult<String> update(@RequestBody @Validated AestheticEducationBasicUpdateDto dto) {
        AestheticEducationBasic aestheticEducationBasic = new AestheticEducationBasic();
        BeanUtils.copyProperties(dto, aestheticEducationBasic);
        if (iAestheticEducationBasicService.updateById(aestheticEducationBasic)) {
            return CommonResult.success("更新成功");
        }
        return CommonResult.failed("更新失败");
    }

    /**
     * 查询德育基本分
     *
     * @return
     */
    @GetMapping
    @ApiOperation("查询德育基本分 aestheticEducation_get")
    @PreAuthorize("hasAuthority('aestheticEducation_get')")
    public CommonResult<IPage<AestheticEducationBasicGetVo>> getPage(AestheticEducationBasicGetDto dto) {
        return iAestheticEducationBasicService.getPage(dto);
    }
    
}

